package cn.wolfcode.demo;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@MapperScan("cn.wolfcode.demo.mapper")
public class MongodbvueApplication {

    public static void main(String[] args) {

        SpringApplication.run(MongodbvueApplication.class, args);
    }


    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            //重学父类的跨域请求处理接口
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        .allowedOrigins("*")//放行哪些域
                        .allowCredentials(true) //是否发送Cookie信息
                        .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")//放行哪些请求
                        .allowedHeaders("*")//放行哪些头信息
                        .allowedHeaders("version", "v1.0");//自定义头信息
            }
        };

    }


}
